const { Http } = require("../../utils/http");
const { default: WxValidate } = require("../../utils/WxValidate");
Page({
  data: {
    bgImg:[],
    topImg:"",
    distributor_id:""
  },
  // 跳转后关闭当前  遮罩层
  order: function (e) {
    // console.log(this.data.clickShopId);
    console.log(wx.getStorageSync('register'));
    if (wx.getStorageSync('register') == 0 || wx.getStorageSync('register') == null) {
      wx.showModal({
        title: '提示',
        content: "您还未注册，是否先注册",
        success: function (res) {
          if (res.cancel) {
            //点击取消,默认隐藏弹框
          } else {
            //console.log("点击确定");
            //点击确定
            wx.navigateTo({
              url: '../logon/index'
            });
          }
        }
      });
    } else {
      wx.navigateTo({
        url: '/pages/pay/index?distributor_id='+this.data.distributor_id
      });
    }

  },
  onImg:async function (){
   let result = await Http.request({
      url: 'wechat/product/get_detail_by_id',
      data: {id: 4 },
      method: "POST"
   })
   console.log(result);
   if(result.code == 0){
     this.setData({
      topImg:result.data.headerimages,
      bgImg:result.data.arr_images
     })
   console.log(result.data);
   }else{
      console.log("网络有问题");
   }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function (options) {
    console.log(options);
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    
    
    if (options.scene == undefined || options.scene == null || options.scene == "" || options.scene == 0) {
//       console.log('scene 场景值为 null');
          wx.removeStorageSync("scene");
    }else{
   let scene = decodeURIComponent(options.scene);
      // const qcode = decodeURIComponent(options.scene);
      // console.log(qcode);
      console.log( scene );
      wx.setStorageSync('scene', scene );
      let arr = scene.split(",");
      this.setData({
        distributor_id:arr[1]
      })
    }
    setTimeout(() => {
     this.onImg();
     wx.request({
          url: 'https://jordan.james8bond.top/wechat/index/init',
          data: { token: wx.getStorageSync('token') },
          success (res) {
            if(res.data.code == 0){
              // console.log(res);
              wx.setStorageSync('register', res.data.data.register);
              wx.setStorageSync('shoplist', res.data.data.store_list);
              wx.setStorageSync('verifyman', res.data.data.verification);
              wx.setStorageSync('distributor', res.data.data.distributor);
              wx.setStorageSync('user_id', res.data.data.user_id);
              wx.setStorageSync('store_id', res.data.data.store_id);
            }
            console.log(res);
            wx.hideLoading();
          }
        })
    }, 3000);
    
  },
  onShareAppMessage: function () {
    return {
      title: '送自己与闺蜜花之盛宴',
      path: '/pages/register/index',
      imageUrl:'https://img01.yzcdn.cn/upload_files/2021/04/07/Fpwl5yPh14gN4x-EiYJ-JZSWBRI0.jpg'
    }
  }
});